Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 2 - Geometric Shapes / Using Geometric Shapes


Creating and Drawing Rectangles

You can create rectangle shapes and draw rectangles with QuickDraw GX the same way you create and draw points, lines, and curves. Typically, you first define a rectangle geometry, which is encapsulated in a gxRectangle structure:

struct gxRectangle {
   Fixed    left;
   Fixed    top;
   Fixed    right;
   Fixed    bottom;
};
Note
QuickDraw GX allows you to specify rectangle coordinates out of order--that is, you can specify any corner of the rectangle using the first two fields of the rectangle structure and the opposing corner using the third and fourth fields of the rectangle structure.
Once you've defined a rectangle geometry, you can draw the corresponding rectangle without creating a rectangle shape by using the GXDrawRectangle function or you can create a rectangle shape and draw it with the GXDrawShape function, as shown in Listing 2-10.

Listing 2-10 Creating a rectangle shape

void CreateRectangle(void)
{
   gxShape aRectangleShape;
   
   static gxRectangle aRectangleGeometry = {ff(50), ff(50),
                                            ff(150), ff(100)}; 
                                 
   
   aRectangleShape = GXNewRectangle(&aRectangleGeometry);
   
   GXDrawShape(aRectangleShape);
   
   GXDisposeShape(aRectangleShape);
}
This sample function uses the ff macro (which is an alias for the IntegerToFixed macro) to convert integer constants to the fixed-point coordinate values needed to define a rectangle geometry. It then creates a rectangle shape using the GXNewRectangle function (although it could use the GXNewShape function or the GXNewShapeVector function instead) and draws the rectangle using the GXDrawShape function. The result is shown in Figure 2-23.

Figure 2-23 A rectangle

Notice that the rectangle is solid rather than framed. The GXNewRectangle function returns a new rectangle shape with the same shape fill property as the default rectangle shape, which is the even-odd shape fill.

Note
Although initially QuickDraw GX sets the shape fill property of the default rectangle shape to be even-odd shape fill, you may change the default shape fill for rectangles by using the GXGetDefaultShape function to obtain a reference to the default rectangle and then using the GXSetShapeFill function to change its shape fill. You can similarly change the default shape fill for any shape type.
To create a framed rectangle, you can use the GXSetShapeFill function to change the shape fill from even-odd to closed-frame, as shown in Listing 2-11.

Listing 2-11 Creating a framed rectangle

void CreateFramedRectangle(void)
{
   gxShape aRectangleShape;
   
   static gxRectangle aRectangleGeometry = {ff(150), ff(100),
                                            ff(50), ff(50)}; 
                                 
   
   aRectangleShape = GXNewRectangle(&aRectangleGeometry);
   GXSetShapeFill(aRectangleShape, gxClosedFrameFill);
   
   GXDrawShape(aRectangleShape);
}
Figure 2-24 shows the result of Listing 2-11.

Figure 2-24 A framed rectangle

In general, a rectangle can have any shape fill except open-frame shape fill. For more information about rectangle shapes, see "Rectangle Shapes" on page 2-20 and "The Rectangle Structure" on page 2-106.

For more information about the shape fill property, see "Shape Fill" beginning on page 2-12.

For information about the functions you can use to create and draw rectangles, see the description of the GXNewRectangle function on page 2-114 and the GXDrawRectangle function on page 2-160.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help